package cn.gok;

import java.util.HashSet;
import java.util.Objects;

/**
 * @Author: zhengyx
 * @Date: 2022/7/7 9:40
 * @Version 1.0
 */
class Student extends Object{
    private String name;
    private String sex;
    private int age;
    private int sid;

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", sex='" + sex + '\'' +
                ", age=" + age +
                ", sid=" + sid +
                '}';
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public int getSid() {
        return sid;
    }

    public void setSid(int sid) {
        this.sid = sid;
    }

    public Student(String name, String sex, int age, int sid) {
        this.name = name;
        this.sex = sex;
        this.age = age;
        this.sid = sid;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return
                sid == student.sid &&
                        Objects.equals(name, student.name);

    }

    @Override
    public int hashCode() {
        return Objects.hash(name, sid);
    }
}

public class StudetDemo {
    public static void main(String[] args) {
        Student student1=new Student("aa","nan",21,101);
        Student student2=new Student("aa","nan",21,101);
        System.out.println(student1.equals(student2));

        HashSet<Student> set = new HashSet<>();
        set.add(student1);
        set.add(student2);
        System.out.println(set.size());
    }
}
